/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 * Date: 2013.02.15
 */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forab(i, a, b) for (int i = (a); i <= (b); i++)

typedef unsigned char byte;

const int M = 100;
const int inf = M + 1;

char s[M + 1], w[M][M + 1];
int n, sl, wl[M];
byte g[M][M][M][M], f[M][M + 1];

inline void relax( byte &a, byte b )
{
  a = min(a, b);
}

int main()
{
  assert(gets(s)), sl = strlen(s);
  assert(scanf("%d ", &n) == 1 && n <= M);
  forn(i, n)
    assert(gets(w[i])), wl[i] = strlen(w[i]);
  memset(g, inf, sizeof(g));
  forn(i, sl)
    f[i][0] = 0;
  forn(i, sl)
    forn(j, n)
      if (s[i] == w[j][0])
        g[i][i][j][0] = 0;
  for (int l = sl - 1; l >= 0; l--)
  {
    forab(len, 1, sl - l)
    {
      int m = l + len - 1;
      byte &r = f[l][len];
      r = M + 1;
      forn(i, n)
      {
        relax(r, g[l][m][i][wl[i] - 1]);
        forn(j, wl[i] - 1)
          if (g[l][m][i][j] <= M)
            for (int m1 = m + 1; m1 < sl; m1++)
              if (s[m1] == w[i][j + 1])
                relax(g[l][m1][i][j + 1], g[l][m][i][j] + f[m + 1][m1 - m - 1]);
      }
      r++;
      forab(k, 1, len - 1)
        relax(r, f[l][k] + f[l + k][len - k]);
    }
  }
  printf("%d\n", f[0][sl]);
  return 0;
}
